import 'dart:convert';
import 'dart:ffi';
import 'package:explore/tool/radio.dart';
import 'package:fluent_ui/fluent_ui.dart' as fluent;
import 'package:flutter/material.dart' hide Page;
import 'package:provider/provider.dart';
import 'package:very_good_infinite_list/very_good_infinite_list.dart';
import '../provider/person_info.dart';

class Toolweb extends StatefulWidget {
  List list;
  Function agree;
  var reject;
  String name;
  String agreeName;
  List<dynamic> actlist;
  String selectvalue;
  var setvalue;
  Toolweb(
      {super.key,
      required this.name,
      required this.list,
      required this.agree,
      this.agreeName = "",
      this.actlist = const [],
      this.selectvalue = "错误",
      this.setvalue,
      this.reject});

  @override
  State<StatefulWidget> createState() => _Toolweb();
}

class _Toolweb extends State<Toolweb> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
          title: Text(widget.name),
        ),
        // resizeToAvoidBottomInset: false,
        body: Consumer<PersonInfo>(builder: (ctx, person, child) {
          return Container(
              height: double.infinity,
              width: double.infinity,
              padding: const EdgeInsets.only(left: 20, right: 20, top: 20),
              decoration: const BoxDecoration(
                image: DecorationImage(
                  image: AssetImage('image/actBackground.jpg'),
                  fit: BoxFit.cover, // 图片如何适应容器
                ),
              ),
              child: Column(children: [
                Visibility(
                    visible: widget.actlist.isNotEmpty ? true : false,
                    child: Column(
                      children: [
                        singleChoice(
                          items: widget.actlist != [] ? widget.actlist : ["错误"],
                          selectedValue: widget.selectvalue,
                          width: 338,
                          setvalue: widget.setvalue,
                        ),
                        const SizedBox(
                          height: 20,
                        )
                      ],
                    )),
                Expanded(
                    child: InfiniteList(
                  padding: const EdgeInsets.only(top: 0, bottom: 0),
                  itemCount: widget.list.length,
                  onFetchData: () => {},
                  itemBuilder: (context, index) {
                    return ListTile(
                      minVerticalPadding: 0,
                      dense: true,
                      title: Container(
                          padding: const EdgeInsets.all(5),
                          decoration: const BoxDecoration(
                            color: Colors.white,
                            border: Border(
                              bottom: BorderSide(
                                color: fluent.Color.fromARGB(76, 0, 0, 0),
                                width: 1.0,
                              ),
                            ),
                          ),
                          child: Row(
                            children: [
                              Expanded(
                                flex: 1,
                                child: Text(
                                  widget.list[index],
                                  style: const TextStyle(fontSize: 18),
                                ),
                              ),
                              Expanded(
                                flex: 0,
                                child: TextButton(
                                    style: TextButton.styleFrom(
                                      foregroundColor: Colors.white,
                                      backgroundColor: Colors.blue,
                                    ),
                                    onPressed: () => widget.agree(
                                          person,
                                          widget.list[index],
                                        ),
                                    child: Text(widget.agreeName == ""
                                        ? "同意"
                                        : widget.agreeName)),
                              ),
                              widget.reject == null
                                  ? const SizedBox(
                                      width: 10,
                                    )
                                  : Expanded(
                                      flex: 0,
                                      child: Container(
                                        padding:
                                            const EdgeInsets.only(left: 20),
                                        child: TextButton(
                                            style: TextButton.styleFrom(
                                              foregroundColor: Colors.white,
                                              backgroundColor: Colors.blue,
                                            ),
                                            onPressed: () => widget.reject(
                                                  person,
                                                  widget.list[index],
                                                ),
                                            child: const Text(
                                              "拒绝",
                                            )),
                                      )),
                            ],
                          )),
                    );
                  },
                ))
              ]));
        }));
  }
}
